﻿using ServerBase.Config;
using SvCore;
using SvGame.Objects;

namespace SvGame.Logic;

public static partial class GameLogic
{
    // 昏迷
    public static void Unconcious(this IRole me)
    {
        //loger.Warn($"Unconcious: {me.DebugName}");
        // todo Unconcious 代替昏迷

        if (!me.Living)
        {
            return;
        }

        // todo Unconcious nk奖励

        me.FightRemoveAll();

        // todo Unconcious 下坐骑

        me.Message("你的眼前一黑，接着什么也不知道了．．．", EMudColor.HIR);

        me.Comb.LiveState = ELiveState.Unconcious;

        me.StatusCur.Kee = 0;
        me.StatusCur.Sen = 0;

        Announce(me, "unconcious");

        // 苏醒
        //Callout(Rd(100 - me.Talent.Con) + 30, Wakeup, me);
        me.Callout(Rd(100 - me.Talent.Con) + 30, Wakeup);
    }
    // 死亡
    public static void Die(this IRole me)
    {
        //loger.Warn($"Die: {me.DebugName}");
        // todo Die 代替死亡

        if (me.Comb.LiveState == ELiveState.Die)
        {
            return;
        }

        // todo Die 不死

        me.FightRemoveAll();
        me.KillRemoveAll();

        // todo Die clear_condition

        // todo Die 法宝消失

        Announce(me, "dead");

        var killer = me.Comb.LastDamageFrom;
        if (killer != null)
        {
            killer.KillerReward(me);
        }
        else
        {
            me.Chat(ChatChannel.Rumor, $"{me.Name}莫名其妙地死了。");
        }

        // todo Die 下坐骑

        // 制造尸体
        me.CorpseMake();

        // todo Die 掉落

        // todo Die 解散队伍

        // 移动到 地府
        if (me is Player)
        {
            me.Comb.BusyStop();

            me.StatusEff.Kee = 1;
            me.StatusEff.Sen = 1;
            me.StatusCur.Kee = 1;
            me.StatusCur.Sen = 1;

            var player = me as Player;
            player?.Move(DeathRoom);
        }
        else
        {
            me.Room?.RemoveNpc(me.Uid);
        }
    }
    // 苏醒
    public static void Wakeup(IRole me)
    {
        // todo Revive 苏醒其他处理
        me.Message("慢慢地你终于又有了知觉．．．\n", EMudColor.HIY);
        me.Comb.LiveState = ELiveState.Living;
    }

}
